home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wink / source / cdplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  2.8 KB  |  137 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <cdr.h>
  4. #include    <snd.h>
  5. #include    "defs.h"
  6.  
  7. extern BOOL Input();
  8. extern void wrtstr();
  9. extern int  Sel_menu();
  10. extern char *SPCSTR;
  11.  
  12. typedef struct {
  13.     char    min;
  14.     char    sec;
  15.     char    frame;
  16. } CDTIME;
  17.  
  18. static short   cd_act=FALSE;
  19. static int     type=0,strt=0,endt=0;
  20. static int     vol=64,sts=0,no=0,acv=0;
  21. static CDTIME  st,ed;
  22. static CDTIME  *track=NULL;
  23.  
  24. int     CD_open(void)
  25. {
  26.     int     i;
  27.     CDTIME  disc;
  28.  
  29.     if ( track == NULL && 
  30.         (track = (CDTIME *)malloc(sizeof(CDTIME)*99)) == NULL )
  31.         return 1;
  32.  
  33.     do {
  34.         i = cdr_cdinfo(0,&type,&strt,&endt,(char *)track,(char *)&disc);
  35.     } while ( i == CDERR7 );
  36.  
  37. /*********************************
  38.     char tmp[80];
  39.     sprintf(tmp,"%d:%d:%d",disc.min,disc.sec,disc.frame);
  40.     wrtstr(tmp,30,1,0x15);
  41. *********************************/
  42.  
  43.     if ( disc.frame-- <= 0 ) {
  44.     disc.frame = 74;
  45.     if ( disc.sec-- <= 0 ) {
  46.         disc.sec = 59;
  47.         if ( disc.min-- <= 0 )
  48.         return 1;
  49.     }
  50.     }
  51.     if ( i == 0 ) {
  52.         track[endt].min = disc.min;
  53.         track[endt].sec = disc.sec;
  54.         track[endt].frame = disc.frame;
  55.     acv = 1;
  56.     }
  57.  
  58.     return i;
  59. }
  60. void    CD_play()
  61. {
  62.     int  i;
  63.     char tmp[80],ttl[40];
  64.  
  65.     if ( cdr_mphase(0,&sts,&no,(char *)&st,(char *)&ed) != 0 ) {
  66.     wrtstr("CDが正常にセットされていません?",30,1,0x12);
  67.         return;
  68.     }
  69.     if ( sts != 0 )
  70.         cdr_pause(0);
  71.  
  72.     if ( CD_open() != 0 ) {
  73.     wrtstr("CD情報の読み取りに失敗しました",30,1,0x12);
  74.     return;
  75.     }
  76.  
  77.     tmp[0] = '\0'; sprintf(ttl,"曲番(1-%d) ",endt);
  78.     if ( Input(tmp,ttl) != FALSE )
  79.     return;
  80.     if ( (no = atoi(tmp) - 1) < 0 || no >= endt ) no = 0;
  81.  
  82.     SND_elevol_set(1,vol,vol);
  83.     if ( endt > 0 ) {
  84.         for ( i=no ; i < endt && (track[i].min & 0x80) != 0 ; i++ );
  85.         if ( cdr_mtplay(0,(char *)&(track[i]),(char *)&(track[endt])) != 0 )
  86.         wrtstr("正常に演奏出来ません",30,1,0x12);
  87.     }
  88.     if ( track != NULL )
  89.     free(track);
  90.     track = NULL;
  91.     cd_act = TRUE;
  92. }
  93. void    CD_stop()
  94. {
  95.     cdr_mstop(0);
  96.     if ( track != NULL )
  97.     free(track);
  98.     track = NULL;
  99.     cd_act = FALSE;
  100. }
  101. void    CD_endof()
  102. {
  103.     if ( cd_act != FALSE )
  104.         cdr_mstop(0);
  105. }
  106. void    CD_vol()
  107. {
  108.     char    tmp[80];
  109.  
  110.     sprintf(tmp,"%d",vol);
  111.     if ( Input(tmp,"音量(0-127) ") != FALSE )
  112.     return;
  113.     vol = atoi(tmp);
  114.     SND_elevol_set(1,vol,vol);
  115. }
  116. void    CD_menu()
  117. {
  118.     static int  no=ERR;
  119.     static char *menu[]={
  120.     "1 CD演奏する     ",
  121.     "2 CD演奏を止める ",
  122.     "",
  123.     "3 音量を設定する   ",
  124.     NULL };
  125.  
  126.     wrtstr(SPCSTR,30,1,0x1F);
  127.     if ( Sel_menu(menu,30,2,&no) != FALSE )
  128.     return;
  129.  
  130.     if ( no == 0 )
  131.     CD_play();
  132.     else if ( no == 1 )
  133.     CD_stop();
  134.     else if ( no == 2 )
  135.     CD_vol();
  136. }
  137.